package com.xuedian.xuanxuan.web.service.impl;


import com.xuedian.xuanxuan.core.generic.GenericDao;
import com.xuedian.xuanxuan.core.generic.GenericServiceImpl;
import com.xuedian.xuanxuan.web.dao.TokenMapper;
import com.xuedian.xuanxuan.web.model.Token;
import com.xuedian.xuanxuan.web.service.TokenService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TokenServiceImpl extends GenericServiceImpl<Token, Long> implements TokenService {

    @Resource
    private TokenMapper tokenMapper;

    @Override
    public int insert(Token model) {
        return tokenMapper.insertSelective(model);
    }

    @Override
    public int update(Token model) {
        return tokenMapper.updateByPrimaryKeySelective(model);
    }

    @Override
    public int delete(Long id) {
        return tokenMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Token selectById(Long id) {
        return tokenMapper.selectByPrimaryKey(id);
    }

    @Override
    public GenericDao<Token, Long> getDao() {
        return tokenMapper;
    }

    @Override
    public Token selectByToken(String token) {
        final List<Token> list = tokenMapper.selectByToken(token);
        if (list!=null&&list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public Token selectByUserId(Long userId) {
        final List<Token> list = tokenMapper.selectByUserId(userId);
        if (list!=null&&list.size()>0){
            return list.get(0);
        }
        return null;
    }
}
